package com.xiaoj;

import java.util.concurrent.ThreadPoolExecutor;

public class ThreadDemo1 {

    public static void main(String[] args) throws InterruptedException {
        EextendsThread thread = new EextendsThread();
        thread.start();
        for (int i = 0; i < 5; i++) {
            System.out.println("main 线程名 = " + Thread.currentThread().getName() + "次数 = " + i);
            Thread.sleep(1000);
        }
    }
}

class EextendsThread extends Thread{

    private Integer count = 0;
    @Override
    public void run() {
       //在 run 方法中编写自己的逻辑
        while (true){

                System.out.println("继承 Thread 方式，创建线程" + (++count) + " 线程名 = " + Thread.currentThread().getName());
                // 进行睡眠 1 秒
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            //退出线程
            if(count == 3){
                break;
            }
        }
    }
}
